package com.wkbb.basic.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.wkbb.basic.mapper.ImportLogMapper;
import com.wkbb.basic.model.ImportLog;
import com.wkbb.basic.service.ImportLogService;
import com.wkbb.common.base.BaseServiceImpl;
import com.wkbb.common.dto.basic.UserDto;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author luowenyan
 * @version V1.0
 * @className ImportLogServiceImpl
 * @description TODO
 * @date 2019/10/19 20:02
 */
@Service
@Slf4j
public class ImportLogServiceImpl extends BaseServiceImpl<ImportLog> implements ImportLogService {

    @Autowired
    private ImportLogMapper importLogMapper;

    //@TODO 这里暂时不加事务,加了事务，导入excel页面上一直在加载,但是数据却导入成功
    @Override
    @Transactional(propagation = Propagation.SUPPORTS,rollbackFor = Exception.class)
    public void addImportLog(UserDto userDto, Long newOrgId, Short type, Boolean status, String remark) {
        //插入importLog表
        ImportLog importLog = new ImportLog();
        //类型(1老师 2学生)
        importLog.setType(type);
        importLog.setOrgId(newOrgId);
        importLog.setStatus(status);
        importLog.setRemark(remark);
        importLog.setCreateBy(userDto.getName());
        importLog.setUpdateBy(userDto.getName());
        importLogMapper.insert(importLog);
    }
}
